package com.gzhryc.weixin.api.event.msg.resp;

import java.util.ArrayList;
import java.util.List;

import com.gzhryc.common.xml.annotation.XmlElement;
import com.gzhryc.weixin.api.event.msg.EventObject;
import com.gzhryc.weixin.api.event.msg.IEventRespMessage;

/**
 * 图文消息
 * @author 张浩
 * @version 0.1.7
 * 
 */
@XmlElement("xml")
public class NewsRespMessage implements IEventRespMessage{

	@XmlElement
	private String ToUserName;
	@XmlElement
	private String FromUserName;
	@XmlElement
	private Long CreateTime;
	@XmlElement
	private String MsgType = "news";
	@XmlElement
	private Integer ArticleCount;
	@XmlElement
	private Articles Articles;
	
	public String getToUserName() {
		return ToUserName;
	}

	public void setToUserName(String toUserName) {
		ToUserName = toUserName;
	}

	public String getFromUserName() {
		return FromUserName;
	}

	public void setFromUserName(String fromUserName) {
		FromUserName = fromUserName;
	}

	public Long getCreateTime() {
		return CreateTime;
	}

	public void setCreateTime(Long createTime) {
		CreateTime = createTime;
	}

	public String getMsgType() {
		return MsgType;
	}

	public void setMsgType(String msgType) {
		MsgType = msgType;
	}

	public Integer getArticleCount() {
		if(ArticleCount == null){
			ArticleCount = getArticles().getItem().size();
		}
		return ArticleCount;
	}

	public void setArticleCount(Integer articleCount) {
		ArticleCount = articleCount;
	}

	public Articles getArticles() {
		if(this.Articles == null){
			this.Articles = new Articles();
		}
		return this.Articles;
	}

	public void setArticles(Articles articles) {
		Articles = articles;
	}



	public static class Articles {
		@XmlElement
		private List<Article> item;
		
		public Articles(){
			this.item = new ArrayList<Article>();
		}

		public List<Article> getItem() {
			return item;
		}

		public void setItem(List<Article> item) {
			this.item = item;
		}
		
		public void add(Article article){
			this.item.add(article);
		}
	}

	public static class Article {
		@XmlElement
		private String Title;
		@XmlElement
		private String Description;
		@XmlElement
		private String PicUrl;
		@XmlElement
		private String Url;
		
		public String getTitle() {
			return Title;
		}
		public void setTitle(String title) {
			Title = title;
		}
		public String getDescription() {
			return Description;
		}
		public void setDescription(String description) {
			Description = description;
		}
		public String getPicUrl() {
			return PicUrl;
		}
		public void setPicUrl(String picUrl) {
			PicUrl = picUrl;
		}
		public String getUrl() {
			return Url;
		}
		public void setUrl(String url) {
			Url = url;
		}
	}
	
	public static NewsRespMessage create(EventObject entity){
		NewsRespMessage resp = new NewsRespMessage();
		resp.setCreateTime(entity.getCreateTime());
		resp.setFromUserName(entity.getToUserName());
		resp.setToUserName(entity.getFromUserName());
		return resp;
	}
}
